package cn.tedu.sp03.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.User;
import service.UserService;
import web.util.JsonResult;

@Slf4j
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/{userId}")
    public JsonResult<User> getUser(@PathVariable("userId") Integer userId) {
        log.info("获取用户:{}", userId);
        User user = userService.getUser(userId);
        return JsonResult.ok(user);
    }

    @PostMapping("/{userId}/score")
    public JsonResult<?> addScore(@PathVariable("userId") Integer userId, @RequestParam("score") Integer score) {
        userService.addScore(userId, score);
        return JsonResult.ok();
    }
}
